﻿using System;
using System.Data;
using System.Collections.Generic;
using Model;
namespace BLL
{
    /// <summary>
    /// PMS_User
    /// </summary>
    public class PMS_UserBLL
    {
        private readonly DAL.PMS_UserDAL dal = new DAL.PMS_UserDAL();
        public PMS_UserBLL()
        { }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="user">登录名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public PMS_User Login(string user, string pwd)
        {
            return dal.Login(user, pwd);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public PMS_User GetModel(int id)
        {
            return dal.GetModel(id);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public List<PMS_User> GetList(int roleID)
        {
            return dal.GetList(roleID);
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddUpdate(PMS_User model)
        {
            if (model.id <= 0)
            {
                return dal.Add(model);
            }
            else
            {
                return dal.Update(model);
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 用户名是否存在
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public bool Exite(string loginName)
        {
            List<PMS_User> list = dal.GetList("loginName='" + loginName + "'");
            if (list != null && list.Count > 0)
            {
                return true;
            }
            else
                return false;
        }
    }
}

